﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MageWars.GameElements;

namespace MageWars.Support
{
    public class StateMachine
    {

        public StateMachine(Mage Self)
        {
            this.Self = Self;

        }


        public Mage Self
        {
            get;
            set;
        }

        public State CurrentState
        {
            get;
            set;
        }

        public MWAction GetNextAction()
        {
            if (!Self.IsDead)
            {
                var result = CurrentState.GetNextAction();
                while (result.NewState != null)
                {
                    result.NewState.PreviousState = CurrentState;
                    CurrentState = result.NewState;
                    result = CurrentState.GetNextAction();
                }
                return result;
            }
            else
            {
                return new MWAction();
            }
        }

    }

    public abstract class State
    {
        public State(Mage Self)
        {
            this.Self = Self;

        }

        public Mage Self
        {
            get;
            set;
        }

        public State PreviousState
        {
            get;
            set;
        }

        public abstract Node[] GetCamino();
        //private Behavior CurrentBehavior;

        public abstract MWAction GetNextAction();
        /* CurrentBehavior.GetNextAction()
         * 
        */


    }

    public abstract class Transition
    {
        public abstract State WillTransition();
        /*{
        if (EnemigoCerca){
         * return new EnGuardiaState();
         * } else {
         * return null;
         * 
         * }
        }*/
    }

    public abstract class Behavior
    {

        public abstract MWAction GetNextAction();
        public Mage Self
        {
            get;
            set;
        }

        public Mesh World
        {
            get;
            set;
        }


        public abstract Node[] GetCamino();

    }

    public class MWAction
    {
        public float? Direction { get; set; }
        public float? Speed { get; set; }
        public bool Jump { get; set; }
        public bool Fire { get; set; }
        public bool Finished { get; set; }

        public State NewState { get; set; }

        public MWAction() { }
    }


}